export default {
  // 格式化日期
  formatDate(date, format = 'YYYY-MM-DD') {
    if (!date) return '';
    
    const d = new Date(date);
    const year = d.getFullYear();
    const month = String(d.getMonth() + 1).padStart(2, '0');
    const day = String(d.getDate()).padStart(2, '0');
    const hour = String(d.getHours()).padStart(2, '0');
    const minute = String(d.getMinutes()).padStart(2, '0');
    const second = String(d.getSeconds()).padStart(2, '0');

    return format
      .replace('YYYY', year)
      .replace('MM', month)
      .replace('DD', day)
      .replace('HH', hour)
      .replace('mm', minute)
      .replace('ss', second);
  },

  // 获取今天日期
  getToday() {
    return this.formatDate(new Date());
  },

  // 获取本月第一天
  getMonthStart() {
    const date = new Date();
    date.setDate(1);
    return this.formatDate(date);
  },

  // 获取本月最后一天
  getMonthEnd() {
    const date = new Date();
    date.setMonth(date.getMonth() + 1);
    date.setDate(0);
    return this.formatDate(date);
  },

  // 获取最近7天
  getLast7Days() {
    const dates = [];
    for (let i = 6; i >= 0; i--) {
      const date = new Date();
      date.setDate(date.getDate() - i);
      dates.push(this.formatDate(date));
    }
    return dates;
  },

  // 日期比较
  isSameDay(date1, date2) {
    return this.formatDate(date1) === this.formatDate(date2);
  }
};